package com.vadmin.vadminjava.servlet;

import com.alibaba.fastjson.JSONObject;

import com.vadmin.vadminjava.service.AdminPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/******************************************************************************************
 *
 * 这个单独放权限管理、账号管理的东西
 *
 *****************************************************************************************/

@RestController
@RequestMapping ("/AdminPermissionServlet")
public class AdminPermissionServlet {

	@Autowired
	AdminPermissionService adminPermissionService;

	//管理员账号列表
	@RequestMapping(value = {"/adminList"})
	public String apiNodeApplyList(@RequestParam Map<String, Object> params, HttpServletRequest httpServletRequest) {
		JSONObject paramJ = new JSONObject();
		params.keySet().forEach(i -> paramJ.put(i, params.get(i)));
		return adminPermissionService.adminList(paramJ).toJSONString();
	}
	//角色列表
	@RequestMapping(value = {"/roleList"})
	public String roleList(@RequestParam Map<String, Object> params, HttpServletRequest httpServletRequest) {
		JSONObject paramJ = new JSONObject();
		params.keySet().forEach(i -> paramJ.put(i, params.get(i)));
		return adminPermissionService.roleList(paramJ).toJSONString();
	}

	//角色增加
	@RequestMapping(value = {"/roleAdd"})
	public String roleAdd(@RequestParam Map<String, Object> params, HttpServletRequest httpServletRequest) {
		JSONObject paramJ = new JSONObject();
		params.keySet().forEach(i -> paramJ.put(i, params.get(i)));
		return adminPermissionService.roleAdd(paramJ).toJSONString();
	}

	//用户角色修改
	@RequestMapping(value = {"/userRoleEdit"})
	public String userRoleEdit(@RequestParam Map<String, Object> params, HttpServletRequest httpServletRequest) {
		JSONObject paramJ = new JSONObject();
		params.keySet().forEach(i -> paramJ.put(i, params.get(i)));
		return adminPermissionService.userRoleEdit(paramJ).toJSONString();
	}

	//菜单列表
	@RequestMapping(value = {"/menuList"})
	public String menuList(@RequestParam Map<String, Object> params, HttpServletRequest httpServletRequest) {
		JSONObject paramJ = new JSONObject();
		params.keySet().forEach(i -> paramJ.put(i, params.get(i)));
		return adminPermissionService.menuList(paramJ).toJSONString();
	}

	//角色的菜单数据
	@RequestMapping(value = {"/roleMenuList"})
	public String roleMenuList(@RequestParam Map<String, Object> params, HttpServletRequest httpServletRequest) {
		JSONObject paramJ = new JSONObject();
		params.keySet().forEach(i -> paramJ.put(i, params.get(i)));
		return adminPermissionService.roleMenuList(paramJ).toJSONString();
	}

	//角色菜单更新
	@RequestMapping(value = {"/roleMenuUpdate"})
	public String roleMenuUpdate(@RequestParam Map<String, Object> params, HttpServletRequest httpServletRequest) {
		JSONObject paramJ = new JSONObject();
		params.keySet().forEach(i -> paramJ.put(i, params.get(i)));
		return adminPermissionService.roleMenuUpdate(paramJ).toJSONString();
	}


	//用户所属角色的权限，其实就是菜单列表
	@RequestMapping(value = {"/userRolePermission"})
	public String userRolePermission(@RequestParam Map<String, Object> params, HttpServletRequest httpServletRequest) {
		JSONObject paramJ = new JSONObject();
		params.keySet().forEach(i -> paramJ.put(i, params.get(i)));
		return adminPermissionService.userRolePermission(paramJ).toJSONString();
	}

	//删除一级菜单
	@RequestMapping(value = {"/menuDelOfLevel1"})
	public String menuDelOfLevel1(@RequestParam Map<String, Object> params, HttpServletRequest httpServletRequest) {
		JSONObject paramJ = new JSONObject();
		params.keySet().forEach(i -> paramJ.put(i, params.get(i)));
		return adminPermissionService.menuDelOfLevel1(paramJ).toJSONString();
	}

	//删除二级菜单
	@RequestMapping(value = {"/menuDelOfLevel2"})
	public String menuDelOfLevel2(@RequestParam Map<String, Object> params, HttpServletRequest httpServletRequest) {
		JSONObject paramJ = new JSONObject();
		params.keySet().forEach(i -> paramJ.put(i, params.get(i)));
		return adminPermissionService.menuDelOfLevel2(paramJ).toJSONString();
	}



}
